var thisadminpage;
var AdminPageMediator = Objs("view.AdminPageMediator",
	Mediator,
{
	makeList:"",
	modelList:"",
	driType:"",
	engineType:"",
	trans:"",
	want:"",
	contact:"",
	paper:"",
	located:"",
	deliver:"",
	adsource:"",
	initialize: function( name, viewComponent )
	{ 
		AdminPageMediator.$super.initialize.call( this, name, viewComponent );
    	this.adminsummary = this.facade.retrieveProxy( ProxyNames.ADMINSUMMARY_PROXY );
    	this.makeproxy = this.facade.retrieveProxy( ProxyNames.MAKE_PROXY );
    	this.modelproxy = this.facade.retrieveProxy( ProxyNames.MODEL_PROXY );
    	this.searchproxy = this.facade.retrieveProxy( ProxyNames.SEARCHSORT_PROXY );
    	this.statusproxy = this.facade.retrieveProxy( ProxyNames.STATUS_PROXY );
    	this.resourceproxy = this.facade.retrieveProxy( ProxyNames.ADDRESOURCE_PROXY );
    	this.userproxy = this.facade.retrieveProxy( ProxyNames.USER_PROXY );
    	this.companyproxy = this.facade.retrieveProxy( ProxyNames.COMPANY_PROXY );
		this.adminsummary.load();
		this.registerListeners();
		thisadminpage=this;
		
	},
	
	registerListeners: function()
	{ 
		 var adminpage = this.get();
		adminpage.addEventListener( AdminPage.MAKE, this.make, this );
		adminpage.addEventListener( AdminPage.SUMMARY, this.summary, this );
		adminpage.addEventListener( AdminPage.SEARCH, this.search, this );
		adminpage.addEventListener( AdminPage.STATUS, this.status, this );
		adminpage.addEventListener( AdminPage.ADDRESOURCE, this.addresouce, this );
		adminpage.addEventListener( AdminPage.USERS, this.users, this );
		adminpage.addEventListener( AdminPage.TOWERS, this.towers, this );
		adminpage.addEventListener( AdminPage.MAKEREFRESH, this.makerefresh, this );
		adminpage.addEventListener( AdminPage.MODELREFRESH, this.modelrefresh, this );
		adminpage.addEventListener( AdminPage.MAKESAVE, this.savemake, this );
		adminpage.addEventListener(AdminPage.SAVEMODEL, this.savemodel, this );
		adminpage.addEventListener(AdminPage.EDITMAKE, this.editMake, this );
		adminpage.addEventListener(AdminPage.EDITMODEL, this.editModel, this );
		adminpage.addEventListener(AdminPage.ADDITEM, this.additem, this );
		adminpage.addEventListener(AdminPage.EDITITEM, this.edititemcat, this );
		
		
		
	},
	get: function()
	{
		return this.viewComponent;
	},
	unregisterListeners: function()
	{
	},
	listNotificationInterests: function()
	{
		return [
				NotificationNames.SUMMARYDATA,
				NotificationNames.USERDATA,
				NotificationNames.TOWERDATA,
				NotificationNames.MAKEDATA,
				NotificationNames.MODELDATA,
				NotificationNames.MAKES,
				NotificationNames.SEARCH_SORT_LOADED,
				NotificationNames.SEARCH_CRITERIAS_LOADED,
				NotificationNames.SORT_CRITERIAS_LOADED,
				NotificationNames.ASSETDATA,
				NotificationNames.DRI,
				 NotificationNames.TRAN,
				NotificationNames.ENGINE,
				NotificationNames.WANT,
				 NotificationNames.CONTACT,
				 NotificationNames.PAPERWORK,
				 NotificationNames.LOCATED,
				 NotificationNames.DELIVER,
				 NotificationNames.ADSOURCE,
				 NotificationNames.ADDITEM
				 
		];
	},
    handleNotification: function( note )
	{ 
		
		switch (note.getName() )
		{ 
			case NotificationNames.SUMMARYDATA:
				this.setSelection('summary');
				this.setSummarylist();
				break;
			case NotificationNames.USERDATA:
				if(note.getBody().total_count==0)
					$("#usertable").html('');
				else
					this.setUserlist(note.getBody());
				break;
			case NotificationNames.TOWERDATA:
				if(note.getBody().total_count==0)
				$("#towertable").html('');
				else
				this.setTowerlist(note.getBody());
				break;
			case NotificationNames.MAKEDATA:
				if(note.getBody().count==0)
					$("#maketable").html('');
				else
			
				this.setMakelist(note.getBody());
				break;
			case NotificationNames.MODELDATA:
				if(note.getBody().count==0)
					$("#modeltable").html('');
				else
			
				this.setModellist(note.getBody());
				break;
			case NotificationNames.MAKES:
				this.setMakes(note.getBody());
				break;
			case NotificationNames.SEARCH_SORT_LOADED:
				var result = note.getBody();
				
				var searchCount = result.count;
				var searchCriterias = result.searchCriterias;
				
				var sortCount = result.sortCount;
				var sortCriterias = result.sortCriterias;
				
				this.setSearchCriterias(searchCount, searchCriterias);
				
				this.setSortCriterias(sortCount, sortCriterias);
				break;
			case NotificationNames.SEARCH_CRITERIAS_LOADED:
				
				var result = note.getBody();
				
				var searchCount = result.searchCount;
				var searchCriterias = result.searchCriterias;
				
				this.setSearchCriterias(searchCount, searchCriterias);
				break;
			case NotificationNames.SORT_CRITERIAS_LOADED:
				var result = note.getBody();
				var sortCount = result.sortCount;
				var sortCriterias = result.sortCriterias;
				
				this.setSortCriterias(sortCount, sortCriterias);
				
				break;
			case NotificationNames.ASSETDATA:
				var assets=note.getBody();
				this.setengineResource(assets.engineCount,assets.engine);
				this.setdriviterianResource(assets.driCount,assets.drivetrian);
				this.settransmissionResource(assets.transmissionCount,assets.transmission);
				this.setwantResource(assets.wantCount,assets.want);
				this.setcontactResource(assets.contactCount,assets.contact);
				this.setpaperworkResource(assets.paperCount,assets.paperwork);
				this.setlocatedResource(assets.locatedCount,assets.located);
				this.setdeliverResource(assets.deliverCount,assets.deliver);
				this.setadsourceResource(assets.adsourceCount,assets.adsource);
				break;
			case NotificationNames.ENGINE:
				var engine=note.getBody();
				this.setengineResource(engine.engineCount,engine.engine)
				break;
			case NotificationNames.DRI:
				var dri=note.getBody();
				this.setdriviterianResource(dri.driCount,dri.drivetrian)
				break;
			case NotificationNames.TRAN:
				var tran=note.getBody();
				this.settransmissionResource(tran.transmissionCount,tran.transmission)
				break;
			case NotificationNames.WANT:
				var want=note.getBody();
				this.setwantResource(want.wantCount,want.want)
				break;	
			case NotificationNames.CONTACT:
				var contact=note.getBody();
				this.setcontactResource(contact.contactCount,contact.contact)
				break;
			case NotificationNames.PAPERWORK:
			
				var paper=note.getBody();
				this.setpaperworkResource(paper.paperCount,paper.paper)
				break;	
			case NotificationNames.LOCATED:
				var located=note.getBody();
				this.setlocatedResource(located.locatedCount,located.located)
				break;
			case NotificationNames.DELIVER:
				var deliver=note.getBody();
				this.setdeliverResource(deliver.deliverCount,deliver.deliver)
				break;	
			case NotificationNames.ADSOURCE:
				var adsource=note.getBody();
				this.setadsourceResource(adsource.adsourceCount,adsource.adsource)
				break;
			case NotificationNames.ADDITEM:
				//var adsource=note.getBody();
				this.reload();
				break;	
		}
	},
	
	reload:function()
	{
		if(item_id==1)
		{
			currentDriviterianCriteriaPage=1;
			startDriCriteria=0;
			this.resourceproxy.loadDriCriterias();
		}
		if(item_id==2)
		{
			currentEngineCriteriaPage=1;
			startEngineCriteria=0;
			this.resourceproxy.loadEngineCriterias();
		}
		if(item_id==3)
		{
			currentTransmissionCriteriaPage=1;
			startTranCriteria=0;
			this.resourceproxy.loadTranCriterias();
		}
		if(item_id==4)
		{
			currentWantCriteriaPage=1;
			startWantCriteria=0;
			this.resourceproxy.loadWantCriterias();
		}
		if(item_id==5)
		{
			currentContactCriteriaPage=1;
			startContactCriteria=0;
			this.resourceproxy.loadContactCriterias();
		}
		if(item_id==6)
		{
			currentPaperCriteriaPage=1;
			startPaperCriteria=0;
			this.resourceproxy.loadPaperCriterias();
		}
		if(item_id==7)
		{
			currentLocatedCriteriaPage=1;
			startLocatedCriteria=0;
			this.resourceproxy.loadLocatedCriterias();
		}
		if(item_id==8)
		{
			currentDeliverCriteriaPage=1;
			startDeliverCriteria=0;
			this.resourceproxy.loadDeliverCriterias();
		}
		if(item_id==9)
		{	
			currentAdsourceCriteriaPage=1;
			startAdsourceCriteria=0;
			this.resourceproxy.loadAdsourceCriterias();
		}
	},
	additem:function()
	{
		if($("#txtaddItem").val())
		{
			this.resourceproxy.addItem();
		}
		else
		{
			bootbox.alert("Enter Item Name");
		}
	},
	edititemcat:function()
	{
		if($("#txteditItem").val())
		{
			this.resourceproxy.editItem();
		}
		else
		{
			bootbox.alert("Enter Item Name");
		}
	},
		//Set Deliver Crieterias as Table
	setadsourceResource:function(adsourcecount,adsourcedet)
	{  
		$("#adsourcetable").html('');
		this.adsource=adsourcedet;
		var adsourceCriteriaHTML = "<table style=font-size:10px; class='table table-striped'><thead><tr><td><b>Asset Name</b></td></tr></thead>";
		//alert(adsourcedet);
		for(var i=0; i<adsourcedet.length; i++)
		{
		
			var adsourceCriteriaItem = adsourcedet[i];
			adsourceCriteriaHTML+="<tr><td>"+adsourceCriteriaItem.asset_name+"</td><td><div class='btn-group'><a class='btn btn-mini dropdown-toggle' data-toggle='dropdown' href='javascript:void();'><i class='icon-cog'></i><span class='caret'></span></a><ul class='dropdown-menu pull-right'><li><a href='#editItemPopup' role='button' data-toggle='modal' onClick='thisadminpage.onEditAdsource("+i+");'><i class='icon-pencil'></i>&nbsp;&nbsp;Edit</a></li><li><a href='javascript:void();' onClick='thisadminpage.onDeleteAdsource("+i+");'><i class=' icon-trash'></i>&nbsp;&nbsp;Delete</a></li></ul></div></td></tr>"
			
		}
		adsourceCriteriaHTML+="</table>";
		
		$("#adsourcetable").html(adsourceCriteriaHTML);
		
		//START:Pagination
		var pages;
		if(adsourcecount%4==0)
			pages=adsourcecount/4;
		else
			pages=(Math.floor(adsourcecount/4))+1;
		var pagehtml="<div style=float:right;>"
		
		if(pages==1)
		{
			pagehtml+="</div>"
		}
		
		else if(currentAdsourceCriteriaPage==1)
		{
			pagehtml+="<a  href='javascript:void();' class='btn' onclick=thisadminpage.nextAdsourceCriterias(); ><i class='icon-arrow-right'></i></a></div>"
		}
		else if(currentAdsourceCriteriaPage==pages)
		{
			pagehtml+="<a  href='javascript:void();' class='btn' onclick=thisadminpage.previousAdsourceCriterias(); ><i class='icon-arrow-left'></i></a> </div>";
		}
		else
		{
				pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousAdsourceCriterias(); ><i class='icon-arrow-left'></i></a> <a onclick=thisadminpage.nextAdsourceCriterias(); href='javascript:void();' class='btn' ><i class='icon-arrow-right'></i></a></div>";
		}
				
		$("#adsourcetable").append(pagehtml)
	
	},
		
	nextAdsourceCriterias:function()
	{
		startAdsourceCriteria=startAdsourceCriteria+4;
		currentAdsourceCriteriaPage++;
		this.resourceproxy.loadAdsourceCriterias();	
		
	},
	previousAdsourceCriterias:function()
	{
	
		startAdsourceCriteria=startAdsourceCriteria-4;
		currentAdsourceCriteriaPage--;
		this.resourceproxy.loadAdsourceCriterias();	
		
	},
	onEditAdsource:function(itemindex)
	{	
		item_id=9;
		$("#txteditItem").val(this.adsource[itemindex].asset_name)
		$("#editItemPopup").data("itemID", this.adsource[itemindex].asset_id);
	},
	onDeleteAdsource:function(itemindex)
	{
		item_id=9;
		this.resourceproxy.deleteItem(this.adsource[itemindex].asset_id);	
	},
	
		//Set Deliver Crieterias as Table
	setdeliverResource:function(delivercount,deliverdet)
	{  
		$("#delivertable").html('');
		this.deliver=deliverdet;
		var deliverCriteriaHTML = "<table style=font-size:10px; class='table table-striped'><thead><tr><td><b>Asset Name</b></td></tr></thead>";
		
		for(var i=0; i<deliverdet.length; i++)
		{
		
			var deliverCriteriaItem = deliverdet[i];
			deliverCriteriaHTML+="<tr><td>"+deliverCriteriaItem.asset_name+"</td><td><div class='btn-group'><a class='btn btn-mini dropdown-toggle' data-toggle='dropdown' href='javascript:void();'><i class='icon-cog'></i><span class='caret'></span></a><ul class='dropdown-menu pull-right'><li><a href='#editItemPopup' role='button' data-toggle='modal' onClick='thisadminpage.onEditDeliver("+i+");'><i class='icon-pencil'></i>&nbsp;&nbsp;Edit</a></li><li><a href='javascript:void();' onClick='thisadminpage.onDeleteDeliver("+i+");'><i class=' icon-trash'></i>&nbsp;&nbsp;Delete</a></li></ul></div></td></tr>"
			
		}
		deliverCriteriaHTML+="</table>";
		
		$("#delivertable").html(deliverCriteriaHTML);
		
		//START:Pagination
		var pages;
		if(delivercount%4==0)
			pages=delivercount/4;
		else
			pages=(Math.floor(delivercount/4))+1;
		var pagehtml="<div style=float:right;>"
		
		if(pages==1)
		{
			pagehtml+="</div>"
		}
		
		else if(currentDeliverCriteriaPage==1)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.nextDeliverCriterias(); ><i class='icon-arrow-right'></i></a></div>"
		}
		else if(currentDeliverCriteriaPage==pages)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousDeliverCriterias(); ><i class='icon-arrow-left'></i></a> </div>";
		}
		else
		{
				pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousDeliverCriterias(); ><i class='icon-arrow-left'></i></a> <a onclick=thisadminpage.nextDeliverCriterias(); href='javascript:void();' class='btn' ><i class='icon-arrow-right'></i></a></div>";
		}
				
		$("#delivertable").append(pagehtml)
	
	},
		
	nextDeliverCriterias:function()
	{
		startDeliverCriteria=startDeliverCriteria+4;
		currentDeliverCriteriaPage++;
		this.resourceproxy.loadDeliverCriterias();	
		
	},
	previousDeliverCriterias:function()
	{
	
		startDeliverCriteria=startDeliverCriteria-4;
		currentDeliverCriteriaPage--;
		this.resourceproxy.loadDeliverCriterias();	
		
	},
	onEditDeliver:function(itemindex)
	{	
		item_id=8;
		$("#txteditItem").val(this.deliver[itemindex].asset_name)
		$("#editItemPopup").data("itemID", this.deliver[itemindex].asset_id);
	},
	
	onDeleteDeliver:function(itemindex)
	{
		item_id=8;
		this.resourceproxy.deleteItem(this.deliver[itemindex].asset_id);	
	},
	
		//Set Located at Crieterias as Table
	setlocatedResource:function(locatedcount,locateddet)
	{  
		$("#locatedtable").html('');
		this.located=locateddet;
		var locatedCriteriaHTML = "<table style=font-size:10px; class='table table-striped'><thead><tr><td><b>Asset Name</b></td></tr></thead>";
		
		for(var i=0; i<locateddet.length; i++)
		{
		
			var locatedCriteriaItem = locateddet[i];
			locatedCriteriaHTML+="<tr><td>"+locatedCriteriaItem.asset_name+"</td><td><div class='btn-group'><a class='btn btn-mini dropdown-toggle' data-toggle='dropdown' href='javascript:void();'><i class='icon-cog'></i><span class='caret'></span></a><ul class='dropdown-menu pull-right'><li><a href='#editItemPopup' role='button' data-toggle='modal' onClick='thisadminpage.onEditLocated("+i+");'><i class='icon-pencil'></i>&nbsp;&nbsp;Edit</a></li><li><a href='javascript:void();' onClick='thisadminpage.onDeleteLocated("+i+");'><i class=' icon-trash'></i>&nbsp;&nbsp;Delete</a></li></ul></div></td></tr>"
			
		}
		locatedCriteriaHTML+="</table>";
		
		$("#locatedtable").html(locatedCriteriaHTML);
		
		//START:Pagination
		var pages;
		if(locatedcount%4==0)
			pages=locatedcount/4;
		else
			pages=(Math.floor(locatedcount/4))+1;
		var pagehtml="<div style=float:right;>"
		
		if(pages==1)
		{
			pagehtml+="</div>"
		}
		
		else if(currentLocatedCriteriaPage==1)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.nextLocatedCriterias(); ><i class='icon-arrow-right'></i></a></div>"
		}
		else if(currentLocatedCriteriaPage==pages)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousLocatedCriterias(); ><i class='icon-arrow-left'></i></a> </div>";
		}
		else
		{
				pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousLocatedCriterias(); ><i class='icon-arrow-left'></i></a> <a onclick=thisadminpage.nextLocatedCriterias(); href='javascript:void();' class='btn' ><i class='icon-arrow-right'></i></a></div>";
		}
				
		$("#locatedtable").append(pagehtml)
	
	},
		
	nextLocatedCriterias:function()
	{
		startLocatedCriteria=startLocatedCriteria+4;
		currentLocatedCriteriaPage++;
		this.resourceproxy.loadLocatedCriterias();	
		
	},
	previousLocatedCriterias:function()
	{
	
		startLocatedCriteria=startLocatedCriteria-4;
		currentLocatedCriteriaPage--;
		this.resourceproxy.loadLocatedCriterias();	
		
	},
	onEditLocated:function(itemindex)
	{	
		item_id=7;
		$("#txteditItem").val(this.located[itemindex].asset_name)
		$("#editItemPopup").data("itemID", this.located[itemindex].asset_id);
	},
	onDeleteLocated:function(itemindex)
	{
		item_id=7;
		this.resourceproxy.deleteItem(this.located[itemindex].asset_id);	
	},
		//Set PAper work  Crieterias as Table
	setpaperworkResource:function(papercount,paperdet)
	{  
		$("#papertable").html('');
		this.paper=paperdet;
		var paperCriteriaHTML = "<table style=font-size:10px; class='table table-striped'><thead><tr><td><b>Asset Name</b></td></tr></thead>";
		
		for(var i=0; i<paperdet.length; i++)
		{
		
			var paperCriteriaItem = paperdet[i];
			paperCriteriaHTML+="<tr><td>"+paperCriteriaItem.asset_name+"</td><td><div class='btn-group'><a class='btn btn-mini dropdown-toggle' data-toggle='dropdown' href='javascript:void();'><i class='icon-cog'></i><span class='caret'></span></a><ul class='dropdown-menu pull-right'><li><a href='#editItemPopup' role='button' data-toggle='modal' onClick='thisadminpage.onEditPaper("+i+");'><i class='icon-pencil'></i>&nbsp;&nbsp;Edit</a></li><li><a href='javascript:void();' onClick='thisadminpage.onDeletePaper("+i+");'><i class=' icon-trash'></i>&nbsp;&nbsp;Delete</a></li></ul></div></td></tr>"
			
		}
		paperCriteriaHTML+="</table>";
		
		$("#papertable").html(paperCriteriaHTML);
		
		//START:Pagination
		var pages;
		if(papercount%4==0)
			pages=papercount/4;
		else
			pages=(Math.floor(papercount/4))+1;
		var pagehtml="<div style=float:right;>"
		
		if(pages==1)
		{
			pagehtml+="</div>"
		}
		
		else if(currentPaperCriteriaPage==1)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.nextPaperCriterias(); ><i class='icon-arrow-right'></i></a></div>"
		}
		else if(currentPaperCriteriaPage==pages)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousPaperCriterias(); ><i class='icon-arrow-left'></i></a> </div>";
		}
		else
		{
				pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousPaperCriterias(); ><i class='icon-arrow-left'></i></a> <a onclick=thisadminpage.nextPaperCriterias(); href='javascript:void();' class='btn' ><i class='icon-arrow-right'></i></a></div>";
		}
				
		$("#papertable").append(pagehtml)
	
	},
		
	nextPaperCriterias:function()
	{
		startPaperCriteria=startPaperCriteria+4;
		currentPaperCriteriaPage++;
		this.resourceproxy.loadPaperCriterias();	
		
	},
	previousPaperCriterias:function()
	{
	
		startPaperCriteria=startPaperCriteria-4;
		currentPaperCriteriaPage--;
		this.resourceproxy.loadPaperCriterias();	
		
	},
	onEditPaper:function(itemindex)
	{	
		item_id=6;
		$("#txteditItem").val(this.paper[itemindex].asset_name)
		$("#editItemPopup").data("itemID", this.paper[itemindex].asset_id);
	},
	onDeletePaper:function(itemindex)
	{
		item_id=6;
		this.resourceproxy.deleteItem(this.paper[itemindex].asset_id);	
	},
		//Set Contact to Crieterias as Table
	setcontactResource:function(contactcount,contactdet)
	{ 
		$("#contacttable").html('');
		this.contact=contactdet;
		var contactCriteriaHTML = "<table style=font-size:10px; class='table table-striped'><thead><tr><td><b>Asset Name</b></td></tr></thead>";
		
		for(var i=0; i<contactdet.length; i++)
		{
		
			var contactCriteriaItem = contactdet[i];
			contactCriteriaHTML+="<tr><td>"+contactCriteriaItem.asset_name+"</td><td><div class='btn-group'><a class='btn btn-mini dropdown-toggle' data-toggle='dropdown' href='javascript:void();'><i class='icon-cog'></i><span class='caret'></span></a><ul class='dropdown-menu pull-right'><li><a href='#editItemPopup' role='button' data-toggle='modal' onClick='thisadminpage.onEditContact("+i+");'><i class='icon-pencil'></i>&nbsp;&nbsp;Edit</a></li><li><a href='javascript:void();' onClick='thisadminpage.onDeleteContact("+i+");'><i class=' icon-trash'></i>&nbsp;&nbsp;Delete</a></li></ul></div></td></tr>"
			
		}
		contactCriteriaHTML+="</table>";
		$("#contacttable").html(contactCriteriaHTML);
		
		//START:Pagination
		var pages;
		if(contactcount%4==0)
			pages=contactcount/4;
		else
			pages=(Math.floor(contactcount/4))+1;
		var pagehtml="<div style=float:right;>"
		
		if(pages==1)
		{
		 
			pagehtml+="</div>"
		}
		
		else if(currentContactCriteriaPage==1)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.nextContactCriterias(); ><i class='icon-arrow-right'></i></a></div>"
		}
		else if(currentContactCriteriaPage==pages)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousContactCriterias(); ><i class='icon-arrow-left'></i></a> </div>";
		}
		else
		{
				pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousContactCriterias(); ><i class='icon-arrow-left'></i></a> <a onclick=thisadminpage.nextContactCriterias(); href='javascript:void();' class='btn' ><i class='icon-arrow-right'></i></a></div>";
		}
				
		$("#contacttable").append(pagehtml)
	
	},
		
	nextContactCriterias:function()
	{
		startContactCriteria=startContactCriteria+4;
		currentContactCriteriaPage++;
		this.resourceproxy.loadContactCriterias();	
		
	},
	previousContactCriterias:function()
	{
	
		startContactCriteria=startContactCriteria-4;
		currentContactCriteriaPage--;
		this.resourceproxy.loadContactCriterias();	
		
	},
	onEditContact:function(itemindex)
	{	
		item_id=5;
		$("#txteditItem").val(this.contact[itemindex].asset_name)
		$("#editItemPopup").data("itemID", this.contact[itemindex].asset_id);
	},
	onDeleteContact:function(itemindex)
	{
		item_id=5;
		this.resourceproxy.deleteItem(this.contact[itemindex].asset_id);	
	},
		//Set Want to Crieterias as Table
	setwantResource:function(wantcount,wantdet)
	{ 
		$("#wanttable").html('');
		this.want=wantdet;
		var wantCriteriaHTML = "<table style=font-size:10px; class='table table-striped'><thead><tr><td><b>Asset Name</b></td></tr></thead>";
		
		for(var i=0; i<wantdet.length; i++)
		{
		
			var wantCriteriaItem = wantdet[i];
			wantCriteriaHTML+="<tr><td>"+wantCriteriaItem.asset_name+"</td><td><div class='btn-group'><a class='btn btn-mini dropdown-toggle' data-toggle='dropdown' href='javascript:void();'><i class='icon-cog'></i><span class='caret'></span></a><ul class='dropdown-menu pull-right'><li><a href='#editItemPopup' role='button' data-toggle='modal' onClick='thisadminpage.onEditWant("+i+");'><i class='icon-pencil'></i>&nbsp;&nbsp;Edit</a></li><li><a href='javascript:void();' onClick='thisadminpage.onDeleteWant("+i+");'><i class=' icon-trash'></i>&nbsp;&nbsp;Delete</a></li></ul></div></td></tr>"
			
		}
		wantCriteriaHTML+="</table>";
		$("#wanttable").html(wantCriteriaHTML);
		
		//START:Pagination
		var pages;
		if(wantcount%4==0)
			pages=wantcount/4;
		else
			pages=(Math.floor(wantcount/4))+1;
		var pagehtml="<div style=float:right;>"
		
		if(pages==1)
		{
			pagehtml+="</div>"
		}
		
		else if(currentWantCriteriaPage==1)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.nextWantCriterias(); ><i class='icon-arrow-right'></i></a></div>"
		}
		else if(currentWantCriteriaPage==pages)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousWantCriterias(); ><i class='icon-arrow-left'></i></a> </div>";
		}
		else
		{
				pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousWantCriterias(); ><i class='icon-arrow-left'></i></a> <a onclick=thisadminpage.nextWantCriterias(); href='javascript:void();' class='btn' ><i class='icon-arrow-right'></i></a></div>";
		}
				
		$("#wanttable").append(pagehtml)
	
	},
		
	nextWantCriterias:function()
	{
		startWantCriteria=startWantCriteria+4;
		currentWantCriteriaPage++;
		this.resourceproxy.loadWantCriterias();	
		
	},
	previousWantCriterias:function()
	{
	
		startWantCriteria=startWantCriteria-4;
		currentWantCriteriaPage--;
		this.resourceproxy.loadWantCriterias();	
		
	},
	onEditWant:function(itemindex)
	{	
		item_id=4;
		$("#txteditItem").val(this.want[itemindex].asset_name)
		$("#editItemPopup").data("itemID", this.want[itemindex].asset_id);
	},
	onDeleteWant:function(itemindex)
	{
		item_id=4;
		this.resourceproxy.deleteItem(this.want[itemindex].asset_id);	
	},
		//Set Transmission Crieterias as Table
	settransmissionResource:function(transmissioncount,transmissiondet)
	{ 
		$("#transmissiontable").html('');
		this.trans=transmissiondet;
		var transmissionCriteriaHTML = "<table style=font-size:10px; class='table table-striped'><thead><tr><td><b>Asset Name</b></td></tr></thead>";
		
		for(var i=0; i<transmissiondet.length; i++)
		{
		
			var transmissionCriteriaItem = transmissiondet[i];
			transmissionCriteriaHTML+="<tr><td>"+transmissionCriteriaItem.asset_name+"</td><td><div class='btn-group'><a class='btn btn-mini dropdown-toggle' data-toggle='dropdown' href='javascript:void();'><i class='icon-cog'></i><span class='caret'></span></a><ul class='dropdown-menu pull-right'><li><a href='#editItemPopup' role='button' data-toggle='modal' onClick='thisadminpage.onEditTrans("+i+");'><i class='icon-pencil'></i>&nbsp;&nbsp;Edit</a></li><li><a href='javascript:void();' onClick='thisadminpage.onDeleteTrans("+i+");'><i class=' icon-trash'></i>&nbsp;&nbsp;Delete</a></li></ul></div></td></tr>"
			
		}
		transmissionCriteriaHTML+="</table>";
		$("#transmissiontable").html(transmissionCriteriaHTML);
		
		//START:Pagination
		var pages;
		if(transmissioncount%4==0)
			pages=transmissioncount/4;
		else
			pages=(Math.floor(transmissioncount/4))+1;
		var pagehtml="<div style=float:right;>"
		
		if(pages==1)
		{
			pagehtml+="</div>"
		}
		
		else if(currentTransmissionCriteriaPage==1)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.nextTransCriterias(); ><i class='icon-arrow-right'></i></a></div>"
		}
		else if(currentTransmissionCriteriaPage==pages)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousTransCriterias(); ><i class='icon-arrow-left'></i></a> </div>";
		}
		else
		{
				pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousTransCriterias(); ><i class='icon-arrow-left'></i></a> <a onclick=thisadminpage.nextTransCriterias(); href='javascript:void();' class='btn' ><i class='icon-arrow-right'></i></a></div>";
		}
				
		$("#transmissiontable").append(pagehtml)
	
	},
		
	nextTransCriterias:function()
	{
		startTranCriteria=startTranCriteria+4;
		currentTransmissionCriteriaPage++;
		this.resourceproxy.loadTranCriterias();	
		
	},
	previousTransCriterias:function()
	{
	
		startTranCriteria=startTranCriteria-4;
		currentTransmissionCriteriaPage--;
		this.resourceproxy.loadTranCriterias();	
		
	},
	
	onEditTrans:function(itemindex)
	{	
		item_id=3;
		$("#txteditItem").val(this.trans[itemindex].asset_name)
		$("#editItemPopup").data("itemID", this.trans[itemindex].asset_id);
	},
	onDeleteTrans:function(itemindex)
	{
		item_id=3;
		this.resourceproxy.deleteItem(this.trans[itemindex].asset_id);	
	},
	
		//Set Driviterian Crieterias as Table
	setdriviterianResource:function(driviteraincount,driviteraindet)
	{ 
		$("#drivitraintable").html('');
		this.driType=driviteraindet;
		var drivitrainCriteriaHTML = "<table style=font-size:10px; class='table table-striped'><thead><tr><td><b>Asset Name</b></td></tr></thead>";
		
		for(var i=0; i<driviteraindet.length; i++)
		{
		
			var driviterainCriteriaItem = driviteraindet[i];
			drivitrainCriteriaHTML+="<tr><td>"+driviterainCriteriaItem.asset_name+"</td><td><div class='btn-group'><a class='btn btn-mini dropdown-toggle' data-toggle='dropdown' href='javascript:void();'><i class='icon-cog'></i><span class='caret'></span></a><ul class='dropdown-menu pull-right'><li><a href='#editItemPopup' role='button' data-toggle='modal' onClick='thisadminpage.onEditDri("+i+");'><i class='icon-pencil'></i>&nbsp;&nbsp;Edit</a></li><li><a href='javascript:void();' onClick='thisadminpage.onDeleteDri("+i+");'><i class=' icon-trash'></i>&nbsp;&nbsp;Delete</a></li></ul></div></td></tr>"
			
		}
		drivitrainCriteriaHTML+="</table>";
		$("#drivitraintable").html(drivitrainCriteriaHTML);
		
		//START:Pagination
		var pages;
		if(driviteraincount%4==0)
			pages=driviteraincount/4;
		else
			pages=(Math.floor(driviteraincount/4))+1;
		var pagehtml="<div style=float:right;>"
		
		if(pages==1)
		{
			pagehtml+="</div>"
		}
		
		else if(currentDriviterianCriteriaPage==1)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.nextDriviterainCriterias(); ><i class='icon-arrow-right'></i></a></div>"
		}
		else if(currentDriviterianCriteriaPage==pages)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousDriviterainCriterias(); ><i class='icon-arrow-left'></i></a> </div>";
		}
		else
		{
				pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousDriviterainCriterias(); ><i class='icon-arrow-left'></i></a> <a onclick=thisadminpage.nextDriviterainCriterias(); href='javascript:void();' class='btn' ><i class='icon-arrow-right'></i></a></div>";
		}
				
		$("#drivitraintable").append(pagehtml)
	
	},
		
	nextDriviterainCriterias:function()
	{
		startDriCriteria=startDriCriteria+4;
		currentDriviterianCriteriaPage++;
		this.resourceproxy.loadDriCriterias();	
		
	},
	previousDriviterainCriterias:function()
	{
	
		startDriCriteria=startDriCriteria-4;
		currentDriviterianCriteriaPage--;
		this.resourceproxy.loadDriCriterias();	
		
	},
	
	onEditDri:function(itemindex)
	{	
		item_id=1;
		$("#txteditItem").val(this.driType[itemindex].asset_name)
		$("#editItemPopup").data("itemID", this.driType[itemindex].asset_id);
	},
	onDeleteDri:function(itemindex)
	{
		item_id=1;
		this.resourceproxy.deleteItem(this.driType[itemindex].asset_id);	
	},
		//Set Engine Crieterias as Table
	setengineResource:function(enginecount,enginedet)
	{ 
		$("#enginetable").html('');
		this.engineType=enginedet;
		var engineCriteriaHTML = "<table style=font-size:10px; class='table table-striped'><thead><tr><td><b>Asset Name</b></td></tr></thead>";
		
		for(var i=0; i<enginedet.length; i++)
		{
		
			var engineCriteriaItem = enginedet[i];
			engineCriteriaHTML+="<tr><td>"+engineCriteriaItem.asset_name+"</td><td><div class='btn-group'><a class='btn btn-mini dropdown-toggle' data-toggle='dropdown' href='javascript:void();'><i class='icon-cog'></i><span class='caret'></span></a><ul class='dropdown-menu pull-right'><li><a href='#editItemPopup' role='button' data-toggle='modal' onClick='thisadminpage.onEditEngine("+i+");'><i class='icon-pencil'></i>&nbsp;&nbsp;Edit</a></li><li><a href='javascript:void();' onClick='thisadminpage.onDeleteEngine("+i+");'><i class=' icon-trash'></i>&nbsp;&nbsp;Delete</a></li></ul></div></td></tr>"
			
		}
		engineCriteriaHTML+="</table>";
		$("#enginetable").html(engineCriteriaHTML);
		
		//START:Pagination
		var pages;
		if(enginecount%4==0)
			pages=enginecount/4;
		else
			pages=(Math.floor(enginecount/4))+1;
		var pagehtml="<div style=float:right;>"
		
		if(pages==1)
		{
			pagehtml+="</div>"
		}
		
		else if(currentEngineCriteriaPage==1)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.nextEngineCriterias(); ><i class='icon-arrow-right'></i></a></div>"
		}
		else if(currentEngineCriteriaPage==pages)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousEngineCriterias(); ><i class='icon-arrow-left'></i></a> </div>";
		}
		else
		{
				pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousEngineCriterias(); ><i class='icon-arrow-left'></i></a> <a onclick=thisadminpage.nextEngineCriterias(); href='javascript:void();' class='btn' ><i class='icon-arrow-right'></i></a></div>";
		}
				
		$("#enginetable").append(pagehtml)
	
	},
		
	nextEngineCriterias:function()
	{
		startEngineCriteria=startEngineCriteria+4;
		currentEngineCriteriaPage++;
		this.resourceproxy.loadEngineCriterias();	
		
	},
	previousEngineCriterias:function()
	{
	
		startEngineCriteria=startEngineCriteria-4;
		currentEngineCriteriaPage--;
		this.resourceproxy.loadEngineCriterias();	
		
	},
	
	onEditEngine:function(itemindex)
	{	
		item_id=2;
		$("#txteditItem").val(this.engineType[itemindex].asset_name)
		$("#editItemPopup").data("itemID", this.engineType[itemindex].asset_id);
	},
	onDeleteEngine:function(itemindex)
	{
		item_id=2;
		this.resourceproxy.deleteItem(this.engineType[itemindex].asset_id);	
	},
	//Set Sort Crieterias as Table
	
	setSortCriterias:function(sortCount, sortCriterias)
	{
		$("#sorttable").html('');
		var sortCriteriaHTML = "<table style=font-size:10px; class='table table-striped'><thead><tr><td>Asset Name</td><td>Create Date</td></tr></thead>";
		
		for(var i=0; i<sortCriterias.length; i++)
		{
		
			var searchCriteriaItem = sortCriterias[i];
			sortCriteriaHTML+="<tr><td>"+searchCriteriaItem.asset_name+"</td><td>"+searchCriteriaItem.create_date+"</td></tr>"
			
		}
		sortCriteriaHTML+="</table>";
		$("#sorttable").html(sortCriteriaHTML);
		
		//START:Pagination
		var pages;
		if(sortCount%5==0)
			pages=sortCount/5;
		else
			pages=(Math.floor(sortCount/5))+1;
		var pagehtml="<div style=float:right;>"
		
		if(pages==1)
		{
			pagehtml+="</div>"
		}
		
		else if(currentSortCriteriaPage==1)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.nextSortCriterias(); ><i class='icon-arrow-right'></i></a></div>"
		}
		else if(currentSortCriteriaPage==pages)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousSortCriterias(); ><i class='icon-arrow-left'></i></a> </div>";
		}
		else
		{
				pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousSortCriterias(); ><i class='icon-arrow-left'></i></a> <a onclick=thisadminpage.nextSortCriterias(); href='javascript:void();' class='btn' ><i class='icon-arrow-right'></i></a></div>";
		}
				
		$("#sorttable").append(pagehtml)
		//END:Pagination
	},
	nextSortCriterias:function()
	{
		startSortCriteria=startSortCriteria+5;
		currentSortCriteriaPage++;
		this.searchproxy.loadSortCriterias();	
		
	},
	previousSortCriterias:function()
	{
	
		startSortCriteria=startSortCriteria-5;
		currentSortCriteriaPage--;
		this.searchproxy.loadSortCriterias();	
		
	},
	
	//Set Search Crieterias as Table
	setSearchCriterias:function(searchCount, searchCriterias)
	{
	
		$("#searchtable").html('');
		var searchCriteriaHTML = "<table style=font-size:10px; class='table table-striped'><thead><tr><td>Asset Name</td><td>Create Date</td></tr></thead>";
		
		for(var i=0; i<searchCriterias.length; i++)
		{
		
			var searchCriteriaItem = searchCriterias[i];
			searchCriteriaHTML+="<tr><td>"+searchCriteriaItem.asset_name+"</td><td>"+searchCriteriaItem.create_date+"</td></tr>"
			
		}
		searchCriteriaHTML+="</table>";
		$("#searchtable").html(searchCriteriaHTML);
		
		//START:Pagination
		var pages;
		if(searchCount%5==0)
			pages=searchCount/5;
		else
			pages=(Math.floor(searchCount/5))+1;
		var pagehtml="<div style=float:right;>"
		if(pages==1)
		{
			pagehtml+="</div>"
		}
		else if(currentSearchCriteriaPage==1)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.nextSearchCriterias(); ><i class='icon-arrow-right'></i></a></div>"
		}
		else if(currentSearchCriteriaPage==pages)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousSearchCriterias(); ><i class='icon-arrow-left'></i></a> </div>";
		}
		else
		{
				pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousSearchCriterias(); ><i class='icon-arrow-left'></i></a> <a onclick=thisadminpage.nextSearchCriterias(); href='javascript:void();' class='btn' ><i class='icon-arrow-right'></i></a></div>";
		}
				
		$("#searchtable").append(pagehtml)
		//END:Pagination
		
	},
	nextSearchCriterias:function()
	{
		startSearchCriteria=startSearchCriteria+5;
		currentSearchCriteriaPage++;
		this.searchproxy.loadSearchCriterias();	
		
	},
	previousSearchCriterias:function()
	{
	
		startSearchCriteria=startSearchCriteria-5;
		currentSearchCriteriaPage--;
		this.searchproxy.loadSearchCriterias();	
		
	},
	
	
	savemodel:function()
	{
	
		this.modelproxy.save();
	},
	getmakes:function()
	{
	
		this.makeproxy.getmakes();
	},
	setMakes:function(allmakes)
	{
		var makehtml=''
			$("#makecombo").html('');
		$("#editModelMakeCombo").html('');
		for(i=0;i<allmakes.makes.length;i++)
		{
			makehtml+="<option value="+allmakes.makes[i].make_id+">"+allmakes.makes[i].make+"</option>";
		}
		
		$("#makecombo").append(makehtml);
		$("#editModelMakeCombo").append(makehtml);
		//alert($("#makecombo").val());
		
	},
	savemake:function()
	{
	if($("#make").val())
	 this.makeproxy.save();
	 else
	 alert("Add make name");
	},
	make:function()
	{
	    this.setSelection('make');
		this.makeproxy.load();
		this.modelproxy.load();
		this.getmakes();
	},
	makerefresh:function()
	{
		startmake=0;
		countmake=5;
		currentpagemake=1;
	   
		this.makeproxy.load();
	},
	summary:function()
	{
		this.setSelection('summary');
		
	},
	modelrefresh:function()
	{
		startmodel=0;
		countmodel=5;
		currentpagemodel=1;
	
		this.modelproxy.load();
	},
	search:function()
	{
		this.setSelection('search');
		this.searchproxy.load();
		
	},
	status:function()
	{
		this.setSelection('status');
		this.statusproxy.load();
	},
	addresouce:function()
	{
		this.setSelection('addresource');
		this.resourceproxy.load();
	},
	users:function()
	{
		this.setSelection('user');
	
		this.userproxy.load();	
	
	},
	towers:function()
	{
		this.setSelection('tower');
	
		this.companyproxy.load();	
	},
	//Set Model List as Table
	setModellist:function(modellists)
	{
	
		this.modelList = modellists.models;
		var morelisthtml="<table style=font-size:10px; class='table table-striped'><thead><tr><td>Name</td> <td>Make</td><td>Edit/Delete</td></tr></thead>";
		for(i=0;i<modellists.models.length;i++)
		{
			morelisthtml+="<tr><td>"+modellists.models[i].model_name+"</td><td>"+modellists.models[i].make+"</td><td><div class='btn-group'><a class='btn btn-mini dropdown-toggle' data-toggle='dropdown' href='javascript:void();'><i class='icon-cog'></i><span class='caret'></span></a><ul class='dropdown-menu pull-right'><li><a href='#editModelPopup' role='button' data-toggle='modal' onClick='thisadminpage.onEditModel("+i+");'><i class='icon-pencil'></i>&nbsp;&nbsp;Edit</a></li><li><a href='javascript:void();' onClick='thisadminpage.onDeleteModel("+i+");'><i class=' icon-trash'></i>&nbsp;&nbsp;Delete</a></li></ul></div></td></tr>";
			
		}
		morelisthtml+="</table>";
		
		$("#modeltable").html(morelisthtml);
		
		//Pagination
		var pages;
		if(modellists.count%5==0)
			pages=modellists.count/5;
		else
			pages=(Math.floor(modellists.count/5))+1;
			
		var pagehtml="<div style=float:right;>"
		
		if(pages==1)
		{
			pagehtml+="</div>"
		}
		else if(currentpagemodel==1)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.nextmodel(); ><i class='icon-arrow-right'></i></a></div>"
		}
		else if(currentpagemodel==pages)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousmodel(); ><i class='icon-arrow-left'></i></a> </div>";
		}
		else
		{
				pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousmodel(); ><i class='icon-arrow-left'></i></a> <a onclick=thisadminpage.nextmodel(); href='javascript:void();' class='btn' ><i class='icon-arrow-right'></i></a></div>";
		}
		
	
				
		$("#modeltable").append(pagehtml)
	},
	nextmodel:function()
	{
		startmodel=startmodel+5;
		currentpagemodel++;
		this.modelproxy.load();	
		
	},
	previousmodel:function()
	{
	
		startmodel=startmodel-5;
		currentpagemodel--;
		this.modelproxy.load();	
		
	},
	setMakelist:function(makelists)
	{
	
		this.makeList = makelists.makes;
		var morelisthtml="<table style=font-size:10px; class='table table-striped'><thead><tr><td>Name</td><td>Edit/Delete</td></tr></thead>";
		for(i=0;i<makelists.makes.length;i++)
		{
			morelisthtml+="<tr><td>"+makelists.makes[i].make+"</td><td><div class='btn-group'><a class='btn btn-mini dropdown-toggle' data-toggle='dropdown' href='javascript:void();'><i class='icon-cog'></i><span class='caret'></span></a><ul class='dropdown-menu pull-right'><li><a href='#editMakePopup' role='button' data-toggle='modal' onClick=thisadminpage.onMakeEdit("+i+");><i class='icon-pencil' ></i>&nbsp;&nbsp;Edit</a></li><li><a href='javascript:void();' onClick=thisadminpage.onMakeDelete("+i+");><i class=' icon-trash'></i>&nbsp;&nbsp;Delete</a></li></ul></div></td></tr>";
			
		}
		morelisthtml+="</table>";
		
		$("#maketable").html(morelisthtml);
		//Pagination
		var pages;
		if(makelists.count%5==0)
			pages=makelists.count/5;
		else
			pages=(Math.floor(makelists.count/5))+1;
		var pagehtml="<div style=float:right;>"
		if(pages==1)
		{
			pagehtml+="</div>"
		}
		else if(currentpagemake==1)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.nextmake(); ><i class='icon-arrow-right'></i></a></div>"
		}
		else if(currentpagemake==pages)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousmake(); ><i class='icon-arrow-left'></i></a> </div>";
		}
		else
		{
				pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previousmake(); ><i class='icon-arrow-left'></i></a> <a onclick=thisadminpage.nextmake(); href='javascript:void();' class='btn' ><i class='icon-arrow-right'></i></a></div>";
		}
		
		
				
		$("#maketable").append(pagehtml)
	},
	nextmake:function()
	{
		startmake=startmake+5;
		currentpagemake++;
		this.makeproxy.load();	
		
	},
	previousmake:function()
	{
	
		startmake=startmake-5;
		currentpagemake--;
		this.makeproxy.load();	
		
	},
	onEditModel:function(j)
	{
		
		
		$("#editModelMakeCombo").val(this.modelList[j].make_id);
		$("#txtEditModel").val(this.modelList[j].model_name);
		$("#txtEditModelDescription").val(this.modelList[j].model_description);
		$("#editModel").data("modelID", this.modelList[j].model_id);
		
		
	},
	
	editModel:function()
	{
		
		var modelobj=new Object()
		modelobj.modelID=$("#editModel").data("modelID");
		modelobj.makeID=$("#editModelMakeCombo").val();
		modelobj.model=$("#txtEditModel").val();
		modelobj.description=$("#txtEditModelDescription").val();
		modelobj.updatedBy=global_user.admin_id;
		
		this.modelproxy.updatemodel(modelobj);
	
	},
	onDeleteModel:function(i)
	{
		
		var modelObj=new Object();
		
		modelObj.modelID=this.modelList[i].model_id;
		this.modelproxy.deleteModel(modelObj);
		
	},
	onMakeEdit:function(i)
	{
	
		

		$("#txtEditMake").val(this.makeList[i].make);
		$("#editMakeDescription").val(this.makeList[i].description);
		
		$("#editMake").data("makeID", this.makeList[i].make_id);
	},
	editMake:function()
	{

		var makeObj=new Object();
		
		makeObj.makeID=$("#editMake").data("makeID");
		makeObj.make=$("#txtEditMake").val();
		makeObj.description=$("#editMakeDescription").val();
		makeObj.updateBy=global_user.admin_id;
		
		
		this.makeproxy.editMake(makeObj);
		
	},
	onMakeDelete:function(i)
	{
		
		var makeObj=new Object();
		
		makeObj.makeID=this.makeList[i].make_id;
		this.makeproxy.deleteMake(makeObj);
		
	},
	
	setUserlist:function(userlists)
	{
		
		var morelisthtml="<table style=font-size:10px; class='table table-striped'><thead><tr><td>Name</td><td>Email</td><td>Admintype</td><td>Edit/Delete</td></tr></thead>";
		for(i=0;i<userlists.userlist.length;i++)
		{
			morelisthtml+="<tr><td>"+userlists.userlist[i].first_name+" "+userlists.userlist[i].last_name+"</td><td>"+userlists.userlist[i].email+"</td><td>"+userlists.userlist[i].admin_type+"</td><td><div class='btn-group'><a class='btn btn-mini dropdown-toggle' data-toggle='dropdown' href='javascript:void();'><i class='icon-cog'></i><span class='caret'></span></a><ul class='dropdown-menu pull-right'><li><a href='javascript:void();'><i class='icon-pencil'></i>&nbsp;&nbsp;Edit</a></li><li><a href='javascript:void();'><i class=' icon-trash'></i>&nbsp;&nbsp;Delete</a></li></ul></div></td></tr>";
			
		}
		morelisthtml+="</table>";
		
		$("#usertable").html(morelisthtml);
		//Pagination
		var pages;
		if(userlists.total_count%12==0)
			pages=userlists.total_count/12;
		else
			pages=(Math.floor(userlists.total_count/12))+1;
		var pagehtml="<div style=float:right;>"
		
		if(pages==1)
		{
			pagehtml+="</div>"
		}
		else if(currentpage==1)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.next(); ><i class='icon-arrow-right'></i></a></div>"
		}
		else if(currentpage==pages)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previous(); ><i class='icon-arrow-left'></i></a> </div>";
		}
		else
		{
				pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previous(); ><i class='icon-arrow-left'></i></a> <a onclick=thisadminpage.next(); href='javascript:void();' class='btn' ><i class='icon-arrow-right'></i></a></div>";
		}
		
		
				
		$("#usertable").append(pagehtml)
		//---------------------------
		
	},

	next:function()
	{
		start=start+12;
		currentpage++;
		this.userproxy.load();	
		
	},
	previous:function()
	{
	
		start=start-12;
		currentpage--;
		this.userproxy.load();	
		
	},
	setTowerlist:function(towerlists)
	{
	
	var morelisthtml="<table style=font-size:10px; class='table table-striped'><thead><tr><td>Name</td><td>City</td><td>Street</td><td>Edit/Delete</td></tr></thead>";
		for(i=0;i<towerlists.companylist.length;i++)
		{
			morelisthtml+="<tr><td>"+towerlists.companylist[i].company_name+"</td><td>"+towerlists.companylist[i].city+"</td><td>"+towerlists.companylist[i].street+"</td><td><div class='btn-group'><a class='btn btn-mini dropdown-toggle' data-toggle='dropdown' href='javascript:void();'><i class='icon-cog'></i><span class='caret'></span></a><ul class='dropdown-menu pull-right'><li><a href='javascript:void();'><i class='icon-pencil'></i>&nbsp;&nbsp;Edit</a></li><li><a href='javascript:void();'><i class=' icon-trash'></i>&nbsp;&nbsp;Delete</a></li></ul></div></td></tr>";
			
		}
		morelisthtml+="</table>";
		
		$("#towertable").html(morelisthtml);
		//Pagination
		var pages;
		if(towerlists.total_count%12==0)
			pages=towerlists.total_count/12;
		else
			pages=(Math.floor(towerlists.total_count/12))+1;
		var pagehtml="<div style=float:right;>"
		if(pages==1)
		{
			pagehtml+="</div>"
		}
		else if(currentpagetower==1)
		{
			pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.nexttowerlist(); ><i class='icon-arrow-right'></i></a></div>"
		}
		else 
		{
			if(currentpagetower==pages)
			{
					pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previoustowerlist(); ><i class='icon-arrow-left'></i></a> </div>";
			}
		else
			{
				pagehtml+="<a href='javascript:void();' class='btn' onclick=thisadminpage.previoustowerlist(); ><i class='icon-arrow-left'></i></a> <a onclick=thisadminpage.nexttowerlist(); href='javascript:void();' class='btn' ><i class='icon-arrow-right'></i></a></div>";
			}
		}
		
				
		$("#towertable").append(pagehtml);
	
	},
	nexttowerlist:function()
	{
		starttower=starttower+12;
		currentpagetower++;
		this.companyproxy.load($("#searchtower").val());	
		
	},
	previoustowerlist:function()
	{
	
		starttower=starttower-12;
		currentpagetower--;
		this.companyproxy.load();	
		
	},
	getIdprefixes:function()
	{
		var idarray=['summary','make','search','status','addresource','user','tower'];
		return idarray;
	},
	setSelection:function(selectedpanel)
	{
		var panelarray=this.getIdprefixes();
		for(var i=0;i< panelarray.length;i++)
		{
			$("#"+panelarray[i]+"panel").hide();
			$("#"+panelarray[i]+"li").removeClass('active');
			
		}
			$("#"+selectedpanel+"panel").show();
			$("#"+selectedpanel+"li").addClass('active');
	},
	setSummarylist:function()
	{
		
		$("#summarypanel").html('');
		var userlist=this.adminsummary.getuserarray();
		var companylist=this.adminsummary.getcompanyarray();
		var length;
		
			length=userlist.length;
		var summaryhtml="<div class=row-fluid><div class=span6><h4><i class=icon-list></i><a>Users</a></h4><p><table style=font-size:10px; class='table table-striped'><thead><tr><td>Name</td><td>Email</td><td>Admintype</td></tr></thead>";
		for(i=0;i<userlist.length;i++)
		{
		summaryhtml+="<tr><td>"+userlist[i].fname+" "+userlist[i].lname+"</td><td>"+userlist[i].email+"</td><td>"+userlist[i].type+"</td></tr>"
		}
		summaryhtml+="</table></p>";
		summaryhtml+="<a onclick=thisadminpage.users(); style=float:right; href=#moreuser role=button class='btn btn-primary' data-toggle=modal>More</a>";
		summaryhtml+="</div><div class=span6><h4><i class=icon-list></i><a >Tower Companies</a></h4><p><table style='font-size:10px'; class='table table-striped'><thead><tr><td>Name</td><td>City</td><td>Street</td></tr></thead>"
		for(i=0;i<companylist.length;i++)
		{
			summaryhtml+="<tr><td>"+companylist[i].company_name+"</td><td>"+companylist[i].city+"</td><td>"+companylist[i].street+"</td></tr>"
		}
		summaryhtml+="</table></p>";
		summaryhtml+="<a onclick=thisadminpage.towers(); style=float:right; href=#moreuser role=button class='btn btn-primary' data-toggle=modal>More</a>"
		summaryhtml+="</div></div>";
		$("#summarypanel").html(summaryhtml);
		
		$("#datacontent").show();
		
		$("#progress").hide();
	}
});

